﻿using Abp.Application.Services.Dto;
using Batman.Cms.Core.Controllers;
using Batman.Core;
using Batman.Identity.Controllers.Filters;
using Batman.IdentityServer.Extension.Core.Entities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Linq;

namespace Batman.Identity.Controllers
{
    [MethodControl(PageMethod = true)]
    public class UserController : BatmanController
    {
        public UserManager<User> UserManager { get; set; }

        public UserController(UserManager<User> userManager)
        {
            UserManager = userManager;
        }

        [Authorize("rbac")]
        public ActionResult GetUser(PagedResultRequestDto page, UserFilter filter)
        {
            var query = UserManager.Users.AsNoTracking();

            var items = query.Skip(page.SkipCount).Take(page.MaxResultCount).ToList();
            var total = query.Count();

            var result = new PagedResultDto<User>(total, items);

            return Json(result);
        }

        public ActionResult Test()
        {
            return Json(new { });
        }

        //public ActionResult Login(string username, string password)
        //{
        //    using (var client = new HttpClient())
        //    {

        //        //client.PostAsync("/connect/token", new )
        //    }
        //}
    }
}
